﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PicStore.Model
{
    public class User : DomainBase
    {
        public virtual int UserId { get; set; }
        public virtual string UserName { get; set; }
        public virtual string Email { get; set; }
        public virtual string Department { get; set; }
        public virtual string Phone { get; set; }
        public virtual string Mobile { get; set; }
        public virtual DateTime CreateDate { get; set; }
        public virtual bool IsDeleted { get; set; }
        public virtual Role Role { get; set; }

        public virtual bool IsAuthFor(string controllerName, string actionName)
        {
            var query = from action in Role.Actions
                        where action.ActionUrl.ToLower() == controllerName.ToLower()
                        || action.ActionUrl.ToLower() == controllerName.ToLower() + "/" + actionName.ToLower()
                        select action;

            return query.Any();
        }

        public virtual bool IsAuthFor(string url)
        {
            var query = from action in Role.Actions
                        where action.ActionUrl.ToLower() == url.ToLower()
                        select action;
            return query.Any();
        }
    }
}
